package logic

import (
	"context"
	"projectes/projectrpc/projectrpc"

	"projectes/api/internal/svc"
	"projectes/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type ProductListLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewProductListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ProductListLogic {
	return &ProductListLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *ProductListLogic) ProductList(req *types.ProductListRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	ProductList, err := l.svcCtx.ProjectRpc.ProductList(l.ctx, &projectrpc.ProductListRequest{
		Page:        int64(req.Page),
		Size:        int64(req.Size),
		ProductName: req.ProductName,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Code:    "500",
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Message: "商品展示",
		Code:    "200",
		Data:    ProductList,
	}, nil

}
